package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessPayPassword;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.widget.EditTextWithClear;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/9/30 14:24
 * 修改备注：
 * ================================================
 */
public class SetPayPasswordTwoActivity extends BaseActivity {
    @Bind(R.id.et_password)
    EditTextWithClear etPassword;
    @Bind(R.id.et_confirm_password)
    EditTextWithClear etConfirmPassword;
    @Bind(R.id.bt_confirm)
    Button btConfirm;

    private int type;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_set_pay_password2);
        setTitle("设置支付密码");
    }

    @Override
    public void initMember() {

        // 0 为首次设置支付密码  1为忘记密码
        type = (int) getIntent().getSerializableExtra("type");

    }

    @Override
    public void addListener() {
        btConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String strPassword = StringUtil.getEditText(etPassword);
                String strConfirmPassword = StringUtil.getEditText(etConfirmPassword);

                if (StringUtil.isStrEmpty(strPassword)) {
                    showToast("新密码不能为空");
                    return;
                }

                if (StringUtil.isStrEmpty(strConfirmPassword)) {
                    showToast("确认新密码不能为空");
                    return;
                }

                if (!StringUtil.isStrEqual(strPassword, strConfirmPassword)) {
                    showToast("两次输入的密码不一致");
                    return;
                }


                if (type == 0)
                    BusinessPayPassword.setPayPassword(SetPayPasswordTwoActivity.this, strPassword, strConfirmPassword, mHandler);
                else
                    BusinessPayPassword.setPayPasswordNew(SetPayPasswordTwoActivity.this, strPassword, strConfirmPassword, mHandler);
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_SET_PAY_PASSWORD_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_SET_PAY_PASSWORD_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {
        showToast("密码设置成功!");
        finish();
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
